package yagl.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import sjgl.agent.IsjAgent;
import yagl.agent.YaAgent;
import common.Const;
import common.MyUtils;
import common.BaseClasses.CommonAction;
import common.BaseClasses.util.IocUtil;

public class YaAction extends CommonAction{

	private YaAgent yaAgent;
	private  Map<Object, Object> resultMap;
	public String teamName; 
	public YaAction(){
	    	try {
	    		this.yaAgent=(YaAgent) IocUtil.getIocImpl("yagl/ioc/ioc-ya.xml","yaAgent");
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }
/**
 * 无条件应急队伍查询 
 * @return
 */
	public String selectAllTeam(){
		Map map=new HashMap();
		paramMap.put("returnPageName", "toYjDwFenYePage");
		resultMap=yaAgent.selectAllTm(1,getIntParameter("pageSize"),map);
		setPageParam(resultMap);
		return "toYjdwPage";
	}
	/**
	 * 跳转到编辑页面
	 * @return
	 */
	public void findTmById(){
		List list=yaAgent.findTMById(getParameter("tmId"));
		writeStringToResponse(JSONArray.fromObject(list));
	}

	 /**
     * 点击分页条下的数字触发的分页action
     * @return
     */
    public String findTmByPage(){
    	//分页条件
    	paramMap.put("returnPageName", getParameter("returnPageName"));
    	paramMap.put("teamName", getParameter("teamName",""));
    	Map map=new HashMap();
    	map.put("teamName", getParameter("teamName",""));
    	resultMap=yaAgent.selectAllTm(pageBean.getCurrentPage(), pageBean.getPageSize(), map);
        setPageParam(resultMap);
    	return getParameter("returnPageName");
    }
    /**
     * 根据机构名称查询
     */
    public String searchTm(){
    	Map map=new HashMap();
    	map.put("zzjgTeam", getParameter("name"));
    	System.out.println("-------------"+map);
    	//将查询条件存入到分页标签里面
    	paramMap.put("returnPageName", "toYjDwFenYePage");
    	paramMap.put("teamName", getParameter("name"));
    	resultMap=yaAgent.selectAllTm(1, getIntParameter("pageSize"), map);
    	System.out.println("-------------"+resultMap);
        setPageParam(resultMap);
    	return "toYjDwFenYePage";
    }
    /**
     * 应急队伍添加或更新
     * @return
     */
    public String AddTeam(){
    	String tmid=getParameter("tmId");
    	Map map=new HashMap();
    	if(tmid!=null&&!(tmid.equals(""))){
    		map.put("id", tmid);
    		map.put("team_nm", getParameter("team_nm"));
    		map.put("person", getParameter("cont_nm"));
    		map.put("contact_info", getParameter("cont_tel"));
    		map.put("job", getParameter("job"));
    		map.put("job_respon", getParameter("job_respon"));
    		map.put("eve_type", getParameter("eve_type"));
    		map.put("remark", getParameter("remark"));
    		yaAgent.updataTm(map);
    		return null;
    	}
    	else{
    		map.put("id", MyUtils.getUUID());
    		map.put("team_nm", getParameter("team_nm"));
    		map.put("person", getParameter("cont_nm"));
    		map.put("contact_info", getParameter("cont_tel"));
    		map.put("job", getParameter("job"));
    		map.put("job_respon", getParameter("job_respon"));
    		map.put("eve_type", getParameter("eve_type"));
    		map.put("remark", getParameter("remark"));
    		System.out.println("---------map:"+map);
    		yaAgent.insert(map);
    		return "success";
    	}
    	
    }
    /**
     * 删除所选队伍
     */
    public void DeleteTm(){
    	String tmIdArr=getParameter("teamIDdArr");
    	System.out.println(getParameter("teamIDdArr"));
    	String result=yaAgent.deleteTm(tmIdArr);
    	System.out.println(result);
    	writeStringToResponse(result);
    }
	public YaAgent getYaAgent() {
		return yaAgent;
	}

	public void setYaAgent(YaAgent yaAgent) {
		this.yaAgent = yaAgent;
	}
	public String getTeamName() {
		return teamName;
	}
	public void setTeamName(String teamName) {
		this.teamName = teamName;
	}
	public Map<Object, Object> getResultMap() {
		return resultMap;
	}
	public void setResultMap(Map<Object, Object> resultMap) {
		this.resultMap = resultMap;
	}

	
}
